package io.renren.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.form.SysUserForm;
import io.renren.response.SysUserResponse;
import io.renren.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 用户接口
 * 
 * @author SongR
 *
 */
@RestController
@RequestMapping("/api")
@Api(tags = "用户接口")
public class ApiUserController {

	@Autowired
	SysUserService uService;

	/**
	 * 用户登录
	 * @param user
	 * @return
	 */
	@PostMapping("login")
	@ApiOperation(value="用户登录",response = SysUserResponse.class)
	public R login( @ApiParam(name="user",value="用户信息",type="Object",required=true) SysUserForm user) {
		// 表单校验
		ValidatorUtils.validateEntity(user);
		// 用户登录
		SysUserResponse rUser = uService.login(user);
		return R.ok().put("result", rUser);
	}
	
	/**
	 * 获取所有用户
	 * @return
	 */
	@GetMapping("list")
	@ApiOperation(value="用户列表",response = SysUserResponse.class)
	public R list(){
		List<SysUserResponse> list = uService.selectList();
		return R.ok().put("result", list);
	}

	
	/**
	 * 根据部门获取用户列表
	 * @param deptId
	 * @return
	 */
	public R getByDeptment(Long deptId){
		
		return R.ok();
	}
	
	
	/**
	 * 根据角色获取用户列表
	 * @return
	 */
	public R getByRole(Long roleId){
		
		return R.ok();
	}
	

	/**
	 * 查询用户
	 * @return
	 */
	public R searchUser(String search){
		
		return R.ok();
	}
	
	
	
	
}
